home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16.lha / Python-1.6 / Lib / Python1.6 / distutils / command / clean.py < prev    next >
Encoding:
Python Source  |  2000-08-05  |  3.0 KB  |  85 lines

  1. """distutils.command.clean
  2.  
  3. Implements the Distutils 'clean' command."""
  4.  
  5. # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18
  6.  
  7. __revision__ = "$Id: clean.py,v 1.8 2000/08/05 01:31:54 gward Exp $"
  8.  
  9. import os
  10. from distutils.core import Command
  11. from distutils.dir_util import remove_tree
  12.  
  13. class clean (Command):
  14.  
  15.     description = "clean up output of 'build' command"
  16.     user_options = [
  17.         ('build-base=', 'b',
  18.          "base build directory (default: 'build.build-base')"),
  19.         ('build-lib=', None,
  20.          "build directory for all modules (default: 'build.build-lib')"),
  21.         ('build-temp=', 't',
  22.          "temporary build directory (default: 'build.build-temp')"),
  23.         ('bdist-base=', None,
  24.          "temporary directory for built distributions"),
  25.         ('all', 'a',
  26.          "remove all build output, not just temporary by-products")
  27.     ]
  28.  
  29.     def initialize_options(self):
  30.         self.build_base = None
  31.         self.build_lib = None
  32.         self.build_temp = None
  33.         self.bdist_base = None
  34.         self.all = None
  35.  
  36.     def finalize_options(self):
  37.         self.set_undefined_options('build',
  38.                                    ('build_base', 'build_base'),
  39.                                    ('build_lib', 'build_lib'),
  40.                                    ('build_temp', 'build_temp'))
  41.         self.set_undefined_options('bdist',
  42.                                    ('bdist_base', 'bdist_base'))
  43.  
  44.     def run(self):
  45.         # remove the build/temp.<plat> directory (unless it's already
  46.         # gone)
  47.         if os.path.exists (self.build_temp):
  48.             remove_tree (self.build_temp, self.verbose, self.dry_run)
  49.         else:
  50.             self.warn ("'%s' does not exist -- can't clean it" %
  51.                        self.build_temp)
  52.  
  53.  
  54.             
  55.  
  56.         if self.all:
  57.             # remove the module build directory (unless already gone)
  58.             if os.path.exists (self.build_lib):
  59.                 remove_tree (self.build_lib, self.verbose, self.dry_run)
  60.             else:
  61.                 self.warn ("'%s' does not exist -- can't clean it" %
  62.                            self.build_lib)
  63.  
  64.             # remove the temporary directory used for creating built
  65.             # distributions (default "build/bdist") -- eg. type of
  66.             # built distribution will have its own subdirectory under
  67.             # "build/bdist", but they'll be taken care of by
  68.             # 'remove_tree()'.
  69.             if os.path.exists (self.bdist_base):
  70.                 remove_tree (self.bdist_base, self.verbose, self.dry_run)
  71.             else:
  72.                 self.warn ("'%s' does not exist -- can't clean it" %
  73.                            self.bdist_base)
  74.  
  75.         # just for the heck of it, try to remove the base build directory:
  76.         # we might have emptied it right now, but if not we don't care
  77.         if not self.dry_run:
  78.             try:
  79.                 os.rmdir (self.build_base)
  80.                 self.announce ("removing '%s'" % self.build_base)
  81.             except OSError:
  82.                 pass
  83.  
  84. # class clean
  85.